package com.peisong.controller;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.upload.UploadFile;
import com.peisong.model.Employment;
import com.peisong.model.User;

/**
 * Created by 张凤 on 2016/11/9.
 */
public class IndexController extends Controller {

    /**
     * 注册
     */
    public void register(){
        User user = this.getModel(User.class,"");
         user.save();
        this.renderJson(1);
    }
    public void login(){
        String name=this.getPara("name");
        String password=this.getPara("password");
        Record u = User.dao.login(name, password);
        if(u==null){
           this.renderJson(0);
        }else{
            this.renderJson(u);
        }
    }

    public void updatePassword(){
        String newPassword = this.getPara("newPassword");
        Integer id = this.getParaToInt("id");
        int flag = User.dao.updatePwd(newPassword, id);
        if(flag == 1){
            this.renderJson(1);
        }else{
            this.renderJson(0);
        }
    }

    /**
     * 个人信息修改
     */
    public void updateUser() {
        User user = this.getModel(User.class, "");
        String temp = "/upload/temp/";
        int maxfile = 5 * 1024 * 1024;
        UploadFile uf = getFile("photo",".."+temp, maxfile, "UTF-8");
        user.setPhoto(temp+uf.getFileName());
        user.update();
        this.renderJson("1");
    }
}

